package com.own.component.token.impl;

import com.own.component.token.base.RequestTokenManager;

import javax.servlet.http.HttpServletRequest;

/**
 * DefaultAttributeRequestTokenManager
 *
 * @author chenxueli
 * @date 2023-11-07 18:47:16
 */
public class DefaultAttributeRequestTokenManager implements RequestTokenManager {

    private final String tokenRequestField;

    public DefaultAttributeRequestTokenManager(String tokenRequestField) {
        this.tokenRequestField = tokenRequestField;
    }

    /**
     * 获取token
     *
     * @param request 请求内容
     * @return 登录令牌信息
     */
    @Override
    public String token(HttpServletRequest request) {
        if (request == null) {
            return null;
        }
        var o = request.getAttribute(tokenRequestField);
        return o == null ? null : o.toString();
    }

}
